package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dto.PageResponseResult;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.WmMaterialDto;
import com.sun.xml.bind.v2.model.core.ID;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.media.service.IWmMaterialService;
import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 * 自媒体图文素材信息表 前端控制器
 * </p>
 *
 * @author itheima
 * @since 2022-07-01
 */
@RestController
@RequestMapping("/api/v1/material")
@Api(tags = "自媒体图文素材信息表接口")
@CrossOrigin
public class WmMaterialController{

    @Autowired
    private IWmMaterialService wmMaterialService;


    /**
     * 上传自媒体用户素材
     * @param file 素材文件
     * @return 保存后素材对象
     */
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(@RequestParam("file") MultipartFile file){
        return wmMaterialService.uploadPicture(file);
    }

    /**
     * 查询当前登录自媒体用户素材分页列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public PageResponseResult listByPage(@RequestBody WmMaterialDto dto){
        return wmMaterialService.listByPage(dto);
    }

    /**
     * 素材收藏
     * @param id
     * @return
     */
    @PutMapping("/collect/{id}")
    public ResponseResult footageCollection(@PathVariable("id") Integer id ){
        return wmMaterialService.footageCollection(id);
    }

    /**
     * 取消素材收藏
     * @param id
     * @return
     */
    @PutMapping("/cancel_collect/{id}")
    public ResponseResult unsolicitedFootage(@PathVariable("id") Integer id){
        return wmMaterialService.unsolicitedFootage(id);
    }

    /**
     * 删除素材
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteFootage(@PathVariable("id") Integer id){
        return wmMaterialService.deleteFootage(id);
    }
}
